<template>
    <div>
        <el-dialog v-model="dialogVisible" width="80%" align-center :close-on-click-modal="false" :show-close="false"
            :before-close="handleClose" destroy-on-close draggable>
            <template #header="{ close }">
                <div class="dialog-header flex justify-between items-center">
                    <div>{{ achievementType }}成果展示</div>
                    <el-icon class="el-icon--left cursor-pointer" @click="close">
                        <CircleCloseFilled color="#fff" />
                    </el-icon>
                </div>
            </template>
            <div class="bg-white mt-[10px] pt-[10px]">
                <div class="px-[5px]  text-right" v-if="isView && procInsId != null">
                    <el-link type="primary" @click="checkHistoryModalVisible = true">审核记录</el-link>
                </div>
            </div>
            <div :class="!isView && procInsId ? 'pb-[150px]' : ''">
                <bookView v-if="type == 'book'" :id="id" ref="bookViewRef"></bookView>
                <paperView v-if="type == 'paper'" :id="id" ref="paperViewRef"></paperView>
                <researchReportView v-if="type == 'researchReport'" :id="id" ref="researchReportViewRef">
                </researchReportView>
                <jdProductView v-if="type == 'jdProduct'" :id="id" ref="jdProductViewRef"></jdProductView>
                <artProductView v-if="type == 'artProduct'" :id="id" ref="artProductViewRef"></artProductView>
                <copyRightView v-if="type == 'copyRight'" :id="id" ref="copyRightViewRef"></copyRightView>
                <standardView v-if="type == 'standard'" :id="id" ref="standardViewRef"></standardView>
                <medicineView v-if="type == 'medicine'" :id="id" ref="medicineViewRef"></medicineView>
                <patentView v-if="type == 'patent'" :id="id" ref="patentViewRef"></patentView>
                <breedView v-if="type == 'breed'" :id="id" ref="breedViewRef"></breedView>
                <honorView v-if="type == 'honor'" :id="id" ref="honorViewRef"></honorView>
                <meetingView v-if="type == 'meeting'" :id="id" ref="meetingViewRef"></meetingView>
                <lectureView v-if="type == 'lecture'" :id="id" ref="lectureViewRef"></lectureView>
                <joinMeetingView v-if="type == 'joinMeeting'" :id="id" ref="joinMeetingViewRef"></joinMeetingView>
                <personnelDispatchView v-if="type == 'personnelDispatch'" :id="id" ref="personnelDispatchViewRef">
                </personnelDispatchView>
                <personnelAcceptView v-if="type == 'personnelAccept'" :id="id" ref="personnelAcceptViewRef">
                </personnelAcceptView>
                <paperEmbodyView v-if="type == 'paperEmbody'" :id="id" ref="paperEmbodyViewRef">
                </paperEmbodyView>
                <transformView v-if="type == 'transform'" :id="id" ref="transformViewRef"></transformView>
                <honorApplyBookView v-if="type == 'honorApplyBook'" :id="id" ref="honorApplyBookViewRef">
                </honorApplyBookView>
            </div>
            <template #footer v-if="!isView && procInsId">
                <div class="dialog-footer">
                    <Checkcomponents :procInsId="procInsId" @success="refresh" class="mt-[10px]" />
                </div>
            </template>
        </el-dialog>

    </div>
    <CheckHistoryModal v-model="checkHistoryModalVisible" :procInsId="procInsId" :checker="checker"
        :checkDate="checkDate" />
</template>
<script setup>
import { getbookInfo, getpaperInfo, getreportInfo, getappraisalInfo, getartProductInfo, getpaperEmbodyInfo } from "@/api/achievement/kycg"
import { getcopyRightInfo, getstandardInfo, getmedicineInfo, getpatentInfo, getbreedInfo, getkycgzhInfo } from "@/api/achievement/zscq"
import { gethonorInfo, gethonorApplyBookInfo } from "@/api/achievement/cghj"
import { getmeetingInfo, getlectureInfo, getjoinMeetingInfo, getpersonnelDispatchInfo, getpersonnelAcceptInfo } from "@/api/achievement/xsjl"
import bookView from "@/components/achievementPreview/bookView"
import paperView from "@/components/achievementPreview/paperView"
import researchReportView from "@/components/achievementPreview/researchReportView"
import jdProductView from "@/components/achievementPreview/jdProductView"
import artProductView from "@/components/achievementPreview/artProductView"
import copyRightView from "@/components/achievementPreview/copyRightView"
import standardView from "@/components/achievementPreview/standardView"
import medicineView from "@/components/achievementPreview/medicineView"
import patentView from "@/components/achievementPreview/patentView"
import breedView from "@/components/achievementPreview/breedView"
import honorView from "@/components/achievementPreview/honorView"
import meetingView from "@/components/achievementPreview/meetingView"
import lectureView from "@/components/achievementPreview/lectureView"
import joinMeetingView from "@/components/achievementPreview/joinMeetingView"
import personnelDispatchView from "@/components/achievementPreview/personnelDispatchView"
import personnelAcceptView from "@/components/achievementPreview/personnelAcceptView"
import paperEmbodyView from "@/components/achievementPreview/paperEmbodyView"
import transformView from "@/components/achievementPreview/transformView"
import honorApplyBookView from "@/components/achievementPreview/honorApplyBookView"
import Checkcomponents from "@/views/flowable/processInstance/detail/components.vue";
import CheckHistoryModal from "@/views/project/components/CheckHistoryModal.vue";


const props = defineProps({
    id: String,
    type: String,
    procInsId: String,
    isView: {
        type: Boolean,
        default: true,
    }
})


const checkHistoryModalVisible = ref(false);
const checker = ref("");
const checkDate = ref("");

const refresh = () => {
    dialogVisible.value = false;
    emit('callBack', "")
}

const dialogVisible = defineModel();
const emit = defineEmits(['callBack']);
const handleClose = (done) => {
    // emit('callBack', "")
    done();
}
const close = () => {
    dialogVisible.value = false;
}
const typeArr = [{
    name: '学术著作',
    value: 'book'
}, {
    name: '学术论文',
    value: 'paper'
}, {
    name: '研究报告',
    value: 'researchReport'
}, {
    name: '鉴定成果',
    value: 'jdProduct'
}, {
    name: '艺术作品',
    value: 'artProduct'
}, {
    name: '著作权',
    value: 'copyRight'
}, {
    name: '标准',
    value: 'standard'
}, {
    name: '药证',
    value: 'medicine'
}, {
    name: '专利',
    value: 'patent'
}, {
    name: '获奖成果',
    value: 'honor'
}, {
    name: '新品种',
    value: 'breed'
}, {
    name: '主办会议',
    value: 'meeting'
}, {
    name: '学术讲座',
    value: 'lecture'
}, {
    name: '参加会议',
    value: 'joinMeeting'
}, {
    name: '人员派遣',
    value: 'personnelDispatch'
}, {
    name: '人员接受',
    value: 'personnelAccept'
}, {
    name: '论文收录补录',
    value: 'paperEmbody'
}, {
    name: '科研成果转化',
    value: 'transform'
}, {
    name: '申报获奖',
    value: 'honorApplyBook'
}]
const achievementType = ref('')

const bookViewRef = ref(null)
const paperViewRef = ref(null)
const researchReportViewRef = ref(null)
const jdProductViewRef = ref(null)
const artProductViewRef = ref(null)
const copyRightViewRef = ref(null)
const standardViewRef = ref(null)
const medicineViewRef = ref(null)
const patentViewRef = ref(null)
const breedViewRef = ref(null)
const honorViewRef = ref(null)
const meetingViewRef = ref(null)
const lectureViewRef = ref(null)
const joinMeetingViewRef = ref(null)
const personnelDispatchViewRef = ref(null)
const personnelAcceptViewRef = ref(null)
const paperEmbodyViewRef = ref(null)
const transformViewRef = ref(null)
const honorApplyBookViewRef = ref(null)

const open = () => {
    achievementType.value = typeArr.find(item => item.value === props.type) ? typeArr.find(item => item.value === props.type).name : ''
    switch (props.type) {
        case 'book':
            getbookInfo(props.id).then((res) => {
                bookViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'paper':
            getpaperInfo(props.id).then((res) => {
                paperViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'researchReport':
            getreportInfo(props.id).then((res) => {
                researchReportViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'jdProduct':
            getappraisalInfo(props.id).then((res) => {
                jdProductViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'artProduct':
            getartProductInfo(props.id).then((res) => {
                artProductViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'copyRight':
            getcopyRightInfo(props.id).then((res) => {
                copyRightViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'standard':
            getstandardInfo(props.id).then((res) => {
                standardViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'medicine':
            getmedicineInfo(props.id).then((res) => {
                medicineViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'patent':
            getpatentInfo(props.id).then((res) => {
                patentViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'breed':
            getbreedInfo(props.id).then((res) => {
                breedViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'honor':
            gethonorInfo(props.id).then((res) => {
                honorViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'meeting':
            getmeetingInfo(props.id).then((res) => {
                meetingViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'lecture':
            getlectureInfo(props.id).then((res) => {
                lectureViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'joinMeeting':
            getjoinMeetingInfo(props.id).then((res) => {
                joinMeetingViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'personnelDispatch':
            getpersonnelDispatchInfo(props.id).then((res) => {
                personnelDispatchViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'personnelAccept':
            getpersonnelAcceptInfo(props.id).then((res) => {
                personnelAcceptViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'paperEmbody':
            getpaperEmbodyInfo(props.id).then((res) => {
                paperEmbodyViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'transform':
            getkycgzhInfo(props.id).then((res) => {
                transformViewRef.value.getRuleForm(res.data)
            })
            break;
        case 'honorApplyBook':
            gethonorApplyBookInfo(props.id).then((res) => {
                honorApplyBookViewRef.value.getRuleForm(res.data)
            })
            break;
    }
}


watch(
    () => dialogVisible.value,
    (newValue) => {
        console.log(newValue, 'newValue')
        if (newValue) {
            open()
        }
    },
    { deep: true, immediate: true }
);
</script>
<style scoped lang="scss">
@import url("@/views/achievement/index.scss");
</style>
